// 找主元素
#include<stdio.h>
#define MAXSIZE 1000
int main(){
    int a[MAXSIZE];
    int i=1,n;
    int count=1,count1;
    printf("输入数组长度:\n");
    scanf("%d",&n);
    printf("输入数据:\n");
    for(i=0;i<n;i++){
        scanf_s("%d",&a[i]);
        }
    int c=a[1];    
    while(i<n){
        if(a[i]==c){
            count++;
            if(count>n/2)
                break;
            }
        else if(a[i]!=c&&count>0){
            count--;
        if(count<=0){
            c=a[i];
            count=1;
            }
        }
        i++;
    }
        for(i=0;i<n;i++){
            if(c==a[i])
                count1++;
        }
    if(count1>0)
        printf("%d",c);    
    else    
        printf("%d",-1);
}